﻿angular.module('resources.contactProxy', []);
angular.module('resources.contactProxy').factory('contactProxy', ['rresource', '$http', 'APPSETTING', function (rresource, $http, APPSETTING) {
    var factory = rresource('contact');

    factory.forCustomer = function (customerCode, successcb, failedcb) {
        return factory.query({ customerCode: customerCode }, successcb, failedcb);
    };

    //insert datas to invoice_log table
    //factory.insertDatasForNotice = function (cusNum, invId, messId, conPerson, comms, successcb, failedcb) {

    //    $http({
    //        url: APPSETTING['serverUrl'] + '/api/contact?cusNum=' + cusNum + '&invId=' + invId + '&messId=' + messId + '&conPerson=' + conPerson + '&comms=' + comms,
    //        method: 'POST'
    //    }).success(function (response) {
    //        successcb(response);
    //    }).error(function (ex) {
    //        failedcb(ex);
    //    });
    //};

    //factory.insertDatasForPtp = function (cusNum, invId, messId, conPerson, comms, promissDate, successcb, failedcb) {

    //    $http({
    //        url: APPSETTING['serverUrl'] + '/api/contact?cusNum=' + cusNum + '&invId=' + invId + '&messId=' + messId + '&conPerson=' + conPerson + '&comms=' + comms + '&promissDate=' + promissDate,
    //        method: 'POST'
    //    }).success(function (response) {
    //        successcb(response);
    //    }).error(function (ex) {
    //        failedcb(ex);
    //    });
    //};

    factory.delContactor = function (cusid, successcb, failedcb) {
        $http({
            url: APPSETTING['serverUrl'] + '/api/contact?id=' + cusid,
            method: 'POST'
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    }

    factory.updateContact = function (cont,successcb,failedcb) {
        $http({
            url: APPSETTING['serverUrl'] + '/api/contact',
            method: 'POST',
            data:cont
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    }

    factory.updateCustDomain = function (cont, successcb, failedcb) {
        $http({
            url: APPSETTING['serverUrl'] + '/api/contact?type=domain',
            method: 'POST',
            data: cont
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    }
    factory.delCustDomain = function (cusid, successcb, failedcb) {
        $http({
            url: APPSETTING['serverUrl'] + '/api/contact?domainid=' + cusid,
            method: 'POST'
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    }

    return factory;
} ]);
